package com.mall.controller;
import com.mall.annotation.LoginToken;
import com.mall.annotation.MangerLimit;
import com.mall.dto.ActionResult;
import com.mall.po.Activity;
import com.mall.service.ActityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author zhanghui
 * @ClassName ActivityController
 * @Description 活动
 * @Date 2021/1/6 17:23
 * @Version 1.0
 **/
@Api(tags = "活动相关操作")
@RestController
@RequestMapping("/shangcheng")
public class ActivityController {
    @Autowired
    private ActityService actityService;
    /**
     * @Author zhanghui
     * @Description 根据商品名查询活动信息
     * @Date 2021/1/6 17:24
     * @Param
     * @return
     **/
    @ApiOperation(value = "查询单个活动名称")
    @ApiImplicitParam(name = "goodsname",value = "商品名称",required = true,dataType = "String")
    @RequestMapping(value = "/activityquery",method = RequestMethod.GET)
    public ActionResult activityquery(String goodsname) {
            Activity activity = actityService.findActityByName(goodsname);
            if (actityService.findActityByName(goodsname) != null) {
                return new ActionResult(200,"查询成功",activity);
            }
            return null;
    }
/**
 * @Author zhanghui
 * @Description 添加活动
 * @Date 2021/1/6 18:56
 * @Param
 * @return
 **/
@ApiOperation(value = "添加活动信息")
@ApiImplicitParam(name = "activity",value = "没有活动id的对象（json）",required = true)
@RequestMapping(value = "/activityadd",method = RequestMethod.POST)
public ActionResult activityadd(@RequestBody Activity activity) {
    if (actityService.addActity(activity) > -1) {
        return new ActionResult(200,"添加成功",null);
    }
    return null;
}
/**
 * @Author zhanghui
 * @Description 修改活动
 * @Date 2021/1/6 19:42
 * @Param
 * @return
 **/
@ApiOperation(value = "更新活动内容")
@ApiImplicitParam(name = "activity",value = "更改后的内容",required = true)
@RequestMapping(value = "/activityupdate",method = RequestMethod.PUT)
    public ActionResult activityupdate(@RequestBody Activity activity){
    if(actityService.updateActity(activity)>-1){
        return new ActionResult(200,"修改成功",null);
    }
    return new ActionResult(400,"修改失败",null);
}
/**
 * @Author zhanghui
 * @Description 删除活动
 * @Date 2021/1/6 19:51
 * @Param
 * @return
 **/
@ApiOperation(value = "删除活动")
@ApiImplicitParam(name = "activitysid",value = "要删除目标活动的id",required = true)
@RequestMapping(value = "/activitydel",method = RequestMethod.DELETE)
public ActionResult activityupdate(int activitysid){
    if(actityService.deleteActity(activitysid)>-1){

        return new ActionResult(200,"删除成功",null);
    }
    return new ActionResult(400,"删除失败",null);
}
/**
 * @Author zhanghui
 * @Description 批量删除
 * @Date 2021/1/7 14:28
 * @Param [activitysids]
 * @return com.mall.dto.ActionResult
 **/
@ApiOperation(value = "批量删除活动")
@ApiImplicitParam(name = "activitysids",value = "要删除的活动id数组",required = true)
@RequestMapping(value = "/activitiesdel",method = RequestMethod.DELETE)
    public ActionResult activitiesdel(Integer[] activitysids){
    if(actityService.deleteActityList(activitysids)){
        return new ActionResult(200,"选中的删除成功",null);
    }
    return new ActionResult(400,"选中的删除失败",null);
}
/**
 * @Author zhanghui
 * @Description 分页查询
 * @Date 2021/1/7 16:38
 * @Param [page, pagesize]
 * @return java.util.List<com.mall.po.Activity>
 **/
@ApiOperation(value = "分页获取活动信息列表")
@ApiImplicitParams({
        @ApiImplicitParam(name = "page",value = "查询的页码",required = true ),
        @ApiImplicitParam(name = "pagesize",value = "每一页包含数据条数",required = true)
})
@RequestMapping(value = "/activitysquery",method = RequestMethod.GET)
    public List<Activity> activityquery(int page,int pagesize){
        List<Activity> activitys = actityService.findActivityList(page,pagesize);
        return activitys;
    }
}
